<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单列表</title>
    <link rel="stylesheet" href="media/layui/css/layui.css">

    <script src="media/layui/layui.js"></script>
    <script src="media/js/jquery.min.js"></script>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="media/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="media/js/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>

</head>

<body>



<!--表格的展示-->
<div id="table">
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<!--工具条的显示-->
<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
<!--    <button class="layui-btn" lay-event="detail" >订单详情</button>-->
<!--    <button class="layui-btn" lay-event="cancel">取消</button>-->
    <!--  <a class="layui-btn layui-btn-xs" lay-event="edit">预定</a>-->
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>


<script>
    layui.use(['table', 'laydate', "laypage", "layer", 'carousel', 'upload', 'element'], function(){
        //初始化table组件对象
        var table = layui.table
            ,laypage =layui.laypage//分页的组件
            ,layer = layui.layer//弹框
            ,laydate = layui.laydate//日期组件
            ,element = layui.element;//元素的操作

        //渲染table
        table.render({
            //z找到table  id叫test的组件
            elem: '#test'
            ,id:"table"
            ,url:"seller/order/list"
            ,totalRow: true
            //这个很关键，就是解析 json数据库中数据的 一定要注意键值
            ,cols: [[
                {field:'orderId', title:'订单号', unresize: true, sort: true, fixed:"left"}
                ,{field:'buyerName', title:'买家名字'}
                ,{field:'buyerPhone', title:'手机号'}
                ,{field:'buyerAddress', title:'地址'}
                ,{field:'orderAmount', title:'金额'}
                ,{field:'orderStatus', title:'订单状态',templet: function(item){
                        //    NEW(0,"新订单"),
                        //    FINISHED(1,"完结"),
                        //    CANCLE(2,"已取消"),
                        var str = ""
                        if (item.orderStatus == 0){
                            str = "新订单";
                        }else if (item.orderStatus ==1){
                            str = "完结";
                        }else {
                            str = "已取消";
                        }


                        return '<span style="color: #c00;">'+str +'</span>'
                    }}
                ,{field:'payStatus', title:'支付状态',
                    templet: function(item){
                        //    WAIT(0,"未支付"),
                    //    SUCCESS(1,"支付成功"),
                        var str = ""
                        if (item.payStatus == 0){
                            str = "未支付";
                        }else if (item.payStatus ==1){
                            str = "支付成功";
                        }

                        return '<span style="color: #c00;">'+str +'</span>'
                    }
                }
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width: 300}
            ]]
            ,page: true //分页开启


        });

        /*监听行工具事件*/
        table.on('tool(test)',function (obj) {
            var data = obj.data;
            console.log(data)
            if (obj.event === 'cancel') {
                $.ajax({
                    type:"get",
                    url:"seller/order/cancel?orderId="+ data.orderId,
                    dataType:"json",
                    success:function(data){
                        alert(data.msg);

                        // window.location.href="http://localhost:8080/sell/orderlist.html";
                    },
                    error : function(){
                        alert("ajax加载失败");
                    }

                })
            }
            if(obj.event === 'detail'){
                layer.alert('订单号:' + data.orderId + '<br> 买家名字:' + data.buyerName + '<br> 手机号: ' +
                    data.buyerPhone + '<br>地址:' + data.buyerAddress + '<br>金额: ' + data.orderAmount);
            }

            // if (obj.event === 'detail') {
            //
            //
            //     /* $.ajax({
            //          type:"get",
            //          url:"week/update.do?id="+ data.id,
            //          dataType:"json",
            //          success:function(data){
            //              alert(data.info);
            //              window.location.href="http://localhost:8080/OaNew/week.html";
            //          },
            //          error : function(){
            //              alert("ajax加载失败");
            //          }
            //
            //      })*/
            //
            //     window.location.href = "weekUpdate.html?id=" + data.id
            // }
        })

    });
</script>


<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    修改班级信息
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" id="form1">
                    <div class="form-group">
                        <label for="orderId" class="col-sm-2 control-label">订单号:</label>
                        <div class="col-sm-10">
                            <input class="form-control" name="orderId" id="orderId" type="text" disabled>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="buyerName" class="col-sm-2 control-label">买家名字:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="buyerName" name="buyerName" placeholder="请输入班级名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="buyerPhone" class="col-sm-2 control-label">手机号:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="buyerPhone" name="buyerPhone">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="buyerAddress" class="col-sm-2 control-label">地址:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="buyerAddress" name="buyerAddress" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="orderAmount" class="col-sm-2 control-label">金额:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="orderAmount" name="orderAmount" >
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                        <button type="button" class="btn btn-primary" id="but">
                            提交更改
                        </button>
                    </div>
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

</body>
</html>
